package org.swxjava.servlet;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.swxjava.Container;
import org.swxjava.WebContext;
import org.swxjava.assembler.ConverterManager;

public class DefaultWebContext implements WebContext {

	private ServletConfig config = null;
	private ServletContext context = null;
	private HttpServletRequest request = null;
	private HttpServletResponse response = null;
	private Container container = null;
	private ConverterManager converterManager = null;

	public DefaultWebContext(HttpServletRequest request,
			HttpServletResponse response, ServletConfig config,
			ServletContext context, Container container) {
		this.config = config;
		this.context = context;
		this.container = container;
		this.request = request;
		this.response = response;
	}

	protected ConverterManager getConverterManager() {
		if (converterManager == null) {
			converterManager = container.getConverterManager();
		}
		return converterManager;
	}

	public Container getContainer() {
		return container;
	}

	public ServletConfig getServletConfig() {
		return config;
	}

	public ServletContext getServletContext() {
		return context;
	}

	public HttpSession getSession() {
		return request.getSession();
	}

	public HttpSession getSession(boolean create) {
		return request.getSession(create);
	}

	public HttpServletRequest getHttpServletRequest() {
		return request;
	}

	public HttpServletResponse getHttpServletResponse() {
		return response;
	}
}